from django.contrib.auth.models import Group
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serializers.admin_ser import AdminSerializer
from meiduo_admin.serializers.groups_ser import GroupSerializer
from meiduo_admin.utils import PageNum
from users.models import User


class AdminUserView(ModelViewSet):
    queryset = User.objects.filter(is_staff=True)
    serializer_class = AdminSerializer
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

    def simple(self,request):
        groups = Group.objects.all()
        ser = GroupSerializer(groups, many=True)
        return Response(ser.data)